﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using AccManagerKw.Inventory;
using AccManagerKw.Masters;
using AccManagerKw.Masters.Accounts;
using AccManagerKw.Masters.Item;
using AccManagerKw.Transactions;

namespace AccManagerKw
{
    class ClsMenu
    {
        public void OpenForm(long menuId, FrmMain frmMain)
        {
            switch (menuId)
            {
                #region Masters

                case 1101:
                    CheckIfOpen(new FrmCityMaster(), frmMain);
                    break;
                case 1102:
                    CheckIfOpen(new FrmCountryMaster(), frmMain);
                    break;
                case 1103:
                    CheckIfOpen(new FrmUserMaster(), frmMain);
                    break;
                case 1104:
                    CheckIfOpen(new FrmItemMaster(), frmMain);
                    break;
                case 1105:
                    CheckIfOpen(new FrmStoreMaster(), frmMain);
                    break;
                case 1106:
                    CheckIfOpen(new FrmStateMaster(), frmMain);
                    break;
                case 1107:
                    CheckIfOpen(new FrmItemTypeMaster(), frmMain);
                    break;
                case 1108:
                    CheckIfOpen(new FrmUnitMaster(), frmMain);
                    break;

                case 1109:
                    CheckIfOpen(new FrmAccGroupMaster(), frmMain);
                    break;
                case 1110:
                    CheckIfOpen(new FrmAccountMaster(), frmMain);
                    break;
                #endregion

                #region Inventory
                case 3101:
                    CheckIfOpen(new FrmItemOpStock(), frmMain);
                    break;
                #endregion

                #region Transactions
                case 2101:
                    CheckIfOpen(new FrmPurchaseGoods(), frmMain);
                    break;
                #endregion


                default:
                    break;
            }
        }

        private void CheckIfOpen(Form thisForm, Form parentForm)
        {
            foreach (var f in from Form f in Application.OpenForms where f.Name == thisForm.Name select f)
            {
                f.Focus();
                f.StartPosition = FormStartPosition.CenterScreen;
                return;
            }
            thisForm.MdiParent = parentForm;
            thisForm.StartPosition = FormStartPosition.CenterScreen;
            thisForm.Show();

            // Please Do Not Remove This Line.
            Console.WriteLine("--------{0} - Com Name-> {1}", thisForm.Name, thisForm.CompanyName);
        }
    }
}
